package org.chen;

import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;

public class LettuceConnectTest {
  public static void main(String[] args) {
    //连接到redis的0数据库，uri格式：redis://password@ip/数据库  具体格式参数可以看RedisURI这个类
    RedisClient redisClient = RedisClient.create("redis://192.168.33.113/0");
    StatefulRedisConnection<String, String> connection = redisClient.connect();

    RedisCommands<String, String> sync = connection.sync();

    //测试连接
    System.out.println(sync.ping());

    sync.set("key", "Hello World");
    System.out.println(sync.get("key"));

    connection.close();
    redisClient.shutdown();
  }
}
